package org.liuhy.line
{
	import flash.events.MouseEvent;
	
	import mx.containers.Canvas;
	import mx.core.DragSource;
	import mx.events.DragEvent;
	import mx.managers.CursorManager;
	import mx.managers.DragManager;
	
	import org.CacheUtils;
	import org.liuhy.FlowPanel;
	import org.liuhy.control.UpDownCursor;
	
	public class LineNode extends Canvas
	{	
		public function LineNode(p_x:int,p_y:int)
		{
			this.x = p_x - 3;
			this.y = p_y - 3 ;
			this.width  = 6;
			this.height = 6;
			this.setStyle("borderStyle","solid");
			this.setStyle("borderColor","#FFFFFF");

			this.setStyle("backgroundColor","#FFFFFF");
			this.setStyle("backgroundAlpha","0");
			
			this.addEventListener(MouseEvent.MOUSE_OVER,onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT,onMouseOut);
			
			this.graphics.lineStyle(1, 0x000000);
			this.graphics.moveTo(this.width/2-2,this.height/2-2);
			this.graphics.lineTo(this.width/2+2,this.height/2+2);			
			this.graphics.moveTo(this.width/2-2,this.height/2+2);
			this.graphics.lineTo(this.width/2+2,this.height/2-2);
			
		}
		public function onMouseOver(event:MouseEvent):void{
			 CursorManager.setCursor(UpDownCursor);
		}
		public function onMouseOut(event:MouseEvent):void{
			CursorManager.removeAllCursors();
		}
		public function onMouseMove(event:MouseEvent):void{
			event.stopPropagation();
			var dragInitiator:LineNode = LineNode(event.currentTarget);
            var ds:DragSource = new DragSource();
            ds.addData(this.parent,"line");
            DragManager.doDrag(dragInitiator, ds, event);
            CursorManager.setCursor(UpDownCursor);

		}
		public function onClick(event:MouseEvent):void{
			event.stopPropagation();
		}
		public function get _x():int{
			return this.x + 3;
		}
		public function get _y():int{
			return this.y + 3;
		}
		public function lineNodeDrop(event:DragEvent):void{
			var _flowPanel:FlowPanel = this.parent.parent.parent as FlowPanel;
			CacheUtils.push(_flowPanel.exportXML());
		}
		public function lineNodeVirtualDrag(event:DragEvent):void{
			
		}
		public function lineNodeFocusVirtualDrag(event:DragEvent):void{
			
		}		
	}
}